<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <script type="text/javascript">
        function WebSocketAPIExample() {
            var token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJoYW5nYW5nQHN0ZWVsLmNvbSIsInNjb3BlcyI6WyJURU5BTlRfQURNSU4iXSwidXNlcklkIjoiZjQyYWQ0NjAtNGY3Yy0xMWVkLTlmNGUtMzU3MGE1YzNkNzJjIiwiZW5hYmxlZCI6dHJ1ZSwiaXNQdWJsaWMiOmZhbHNlLCJ0ZW5hbnRJZCI6ImM1ODg4MTcwLTRmN2MtMTFlZC05ZjRlLTM1NzBhNWMzZDcyYyIsImN1c3RvbWVySWQiOiIxMzgxNDAwMC0xZGQyLTExYjItODA4MC04MDgwODA4MDgwODAiLCJpc3MiOiJ0aGluZ3Nib2FyZC5pbyIsImlhdCI6MTY2NzI5MDg0NCwiZXhwIjoxNjY3Mjk5ODQ0fQ.s7WzVeW5f4QytNYU_-aYeNcToMehrQJHL5xYxbI3wYoOyhxReqEi5Fs__3OfsP63MB8h2TzYO4ASqGDxJqmrOA";
            //var entityId = "79ebfa90-bfca-11ec-9975-3be02f4283f7";
            var entityId = "3870b310-5027-11ed-a58c-bdd6245656f6";
            var webSocket = new WebSocket("ws://172.18.0.97:8577/api/ws/plugins/telemetry?token=" + token);

            if (entityId === "YOUR_DEVICE_ID") {
                alert("Invalid device id!");
                webSocket.close();
            }

            if (token === "YOUR_JWT_TOKEN") {
                alert("Invalid JWT token!");
                webSocket.close();
            }

            webSocket.onopen = function () {
                var object = {
                    tsSubCmds: [
                        {
                            entityType: "DEVICE",
                            entityId: entityId,
                            scope: "LATEST_TELEMETRY",
                            cmdId: 10
                        },
                        {
                            entityType: "DEVICE",
                            entityId: "b5aac380-5026-11ed-a58c-bdd6245656f6",
                            scope: "LATEST_TELEMETRY",
                            cmdId: 20
                        }
                    ],
                    historyCmds: [],
                    attrSubCmds: []
                };
                var data = JSON.stringify(object);
                webSocket.send(data);
                alert("Message is sent: " + data);
            };

            webSocket.onmessage = function (event) {
                var received_msg = event.data;
                console.log("Message is received: " + received_msg);
            };

            webSocket.onclose = function (event) {
                alert("Connection is closed!");
            };
        }
    </script>

    <div id="sse">
        <a href="javascript:WebSocketAPIExample()">Run WebSocket</a>
    </div>
</body>
</html>